//
//  DelayAnimation.swift
//  SwiftUIAnimation
//
//  Created by 李煜 on 2024/8/20.
//

import SwiftUI
// 延迟动画 Animation.default.delay(1.0)
struct DelayAnimation: View {
  @State private var isLoading = false
  var body: some View {
    HStack {
      ForEach(0 ... 4, id: \.self) { index in
        Circle()
          .frame(width: 20)
          .foregroundStyle(.green)
          .scaleEffect(isLoading ? 0 : 1)
//          .animation(.linear(duration: 0.5).repeatForever(autoreverses: false).delay(0.1 * Double(index)), value: isLoading)
          .animation(.linear(duration: 0.7).repeatForever(autoreverses: false).delay(0.2 * Double(index)), value: isLoading)
      }
    }
    .onAppear {
      isLoading = true
    }
  }
}

#Preview {
  DelayAnimation()
}
